package com.share.auth.controller;

import com.share.auth.service.UniappService;
import com.share.common.core.domain.Result;
import com.share.common.security.service.TokenService;
import com.share.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 小程序端相关controller 微信登录等接口
 */
@RestController
@Slf4j
public class UniappController {

    @Autowired
    private UniappService uniappService;
    @Autowired
    private TokenService tokenService;

    @GetMapping("/h5/login/{code}")
    public Result<?> wxLogin(@PathVariable String code){
        log.info("微信用户登录：{}",code);
        LoginUser userInfo = uniappService.wxLogin(code);
        Map<String, Object> token = tokenService.createToken(userInfo);
        return Result.ok(token);
    }
}
